<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="Ajax应用, 博客，hexo，live2d，html， css， js， node， vue，">
    <meta name="description" content="">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>Ajax应用 | codeHose9</title>
    <link rel="icon" type="image/png" href="/blog/favicon.png">

    <link rel="stylesheet" type="text/css" href="/blog/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/blog/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/blog/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/blog/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/blog/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/blog/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/blog/css/my.css">

    <script src="/blog/libs/jquery/jquery.min.js"></script>

<meta name="generator" content="Hexo 4.2.1"><link rel="alternate" href="/blog/atom.xml" title="codeHose9" type="application/atom+xml">
<link rel="stylesheet" href="/blog/css/prism-tomorrow.css" type="text/css">
<link rel="stylesheet" href="/blog/css/prism-line-numbers.css" type="text/css"></head>


<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/blog/" class="waves-effect waves-light">
                    
                    <img src="/blog/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">codeHose9</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/blog/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/blog/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/blog/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/blog/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/blog/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/blog/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言板</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/blog/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友情链接</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/blog/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">codeHose9</div>
        <div class="logo-desc">
            
            Never really desperate, only the lost of the soul.
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/blog/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/blog/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/blog/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/blog/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/blog/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/blog/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/blog/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友情链接
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/blinkfox/hexo-theme-matery" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>matery
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/blinkfox/hexo-theme-matery" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="matery" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('/blog/medias/featureimages/4.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">Ajax应用</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/blog/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        margin: 35px 0 15px 0;
        padding-left: 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        height: calc(100vh - 250px);
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/blog/tags/ajax/">
                                <span class="chip bg-color">ajax</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/blog/categories/%E5%89%8D%E7%AB%AF/" class="post-category">
                                前端
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2020-08-06
                </div>
                

                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-check fa-fw"></i>更新日期:&nbsp;&nbsp;
                    2021-01-15
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    1.6k
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-clock fa-fw"></i>阅读时长:&nbsp;&nbsp;
                    6 分
                </div>
                

                
                    <div id="busuanzi_container_page_pv" class="info-break-policy">
                        <i class="far fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv"></span>
                    </div>
				
            </div>
        </div>
        <hr class="clearfix">
        <div class="card-content article-card-content">
            <div id="articleContent">
                <h2 id="一、封装ajax"><a href="#一、封装ajax" class="headerlink" title="一、封装ajax"></a>一、封装ajax</h2><pre class="line-numbers language-highlight js"><span class="function"><span class="keyword">function</span> <span class="title">ajax</span>(<span class="params"><code class="language-highlight js"><span class="function"><span class="keyword">function</span> <span class="title">ajax</span>(<span class="params">options</span>) </span>{
	<span class="comment">// 6. 使用默认值简写options对象</span>
	<span class="keyword">let</span> defaults = {
		type: <span class="string">'get'</span>,
		url: <span class="string">''</span>,
		contentType: <span class="string">'application/x-www-form-urlencoded'</span>,
		data: {},
		success: {},
		error: {}
	}
	<span class="comment">//6.1 options已书写部分替换defaults相同部分</span>
	<span class="built_in">Object</span>.assign(defaults, options);
	<span class="comment">//1. 创建ajax对象</span>
	<span class="keyword">const</span> xhr = <span class="keyword">new</span> XMLHttpRequest();
	<span class="comment">//a 发送数据</span>
	<span class="comment">//a1 拼接数据</span>
	<span class="keyword">let</span> params = <span class="string">''</span>;
	<span class="keyword">for</span> (<span class="keyword">let</span> k <span class="keyword">in</span> defaults.data) {
		params += k + <span class="string">'='</span> + defaults.data[k] + <span class="string">'&'</span>;
	}
	<span class="comment">//a2 除去params字符串最后一个& 符</span>
	params = params.substr(<span class="number">0</span>, params.length - <span class="number">1</span>);

	<span class="comment">//a3 发送get请求方式数据</span>
	defaults.type = defaults.type.toLowerCase();
	<span class="keyword">if</span> (defaults.type === <span class="string">'get'</span>) {
		defaults.url = defaults.url + <span class="string">'?'</span> + params;
	}
	<span class="comment">//2. 告诉ajax请求方式和请求路径</span>
	xhr.open(defaults.type, defaults.url);
	<span class="comment">//a4 发送post请求方式数据</span>
	<span class="keyword">if</span> (defaults.type === <span class="string">'post'</span>) {
		xhr.setRequestHeader(<span class="string">'Content-Type'</span>, defaults.contentType);
		<span class="comment">//a4.1 json数据</span>
		<span class="keyword">if</span> (defaults.contentType === <span class="string">'aplication/json'</span>) {
			xhr.send(<span class="built_in">JSON</span>.stringify(defaults.data));
		} <span class="keyword">else</span> {
			xhr.send(params);
		}
	} <span class="keyword">else</span> {
		<span class="comment">//3. 发送请求</span>
		xhr.send();
	}
	<span class="comment">//4. 接收服务端响应数据</span>
	xhr.onload = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{
		<span class="comment">//4.1 获取响应数据的类型</span>
		<span class="keyword">let</span> responseType = xhr.getResponseHeader(<span class="string">'Content-Type'</span>);
			<span class="keyword">let</span> responseText = xhr.responseText;
		<span class="comment">//4.2 判断是否包含application/json</span>
		<span class="keyword">if</span> (responseType.includes(<span class="string">'application/json'</span>)) {
			<span class="comment">//4.3 转换成json数据</span>
			responseText = <span class="built_in">JSON</span>.parse(responseText);
		}
		<span class="comment">//5 响应不同的http状态码</span>
		<span class="keyword">if</span> (xhr.status === <span class="number">200</span>) {
			defaults.success(responseText);
		} <span class="keyword">else</span> <span class="keyword">if</span> (xhr.status === <span class="number">404</span>) {
			defaults.error(<span class="string">'404页面丢失'</span>);
		} <span class="keyword">else</span> <span class="keyword">if</span> (xhr.status === <span class="number">500</span>) {
			defaults.error(<span class="string">'500服务器bug,网站正在维护...'</span>);
		} <span class="keyword">else</span> {
			defaults.error(<span class="string">'未知错误'</span>);
		}
	}
	xhr.onerror = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>{
		defaults.error(<span class="string">'网络中断...'</span>);
	}
}<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="二、ajax-的使用"><a href="#二、ajax-的使用" class="headerlink" title="二、ajax 的使用"></a>二、ajax 的使用</h2><pre class="line-numbers language-highlight js"><code class="language-highlight js"><!DOCTYPE html>
<html>
	<head>
		<meta charset=<span class="string">"utf-8"</span>>
		<title><<span class="regexp">/title></span>
<span class="regexp">		<style></span>
<span class="regexp">			.success {</span>
<span class="regexp">				color: green;</span>
<span class="regexp">			}</span>
<span class="regexp">			.defail {</span>
<span class="regexp">				color: red;</span>
<span class="regexp">			}</span>
<span class="regexp">		</</span>style>
		<!-- 引用封装好的ajax -->
		<script src=<span class="string">"./ajax.js"</span>><<span class="regexp">/script></span>
<span class="regexp">		<script></span>
<span class="regexp">			/</span><span class="regexp">/ 需求：验证邮箱地址的唯一性</span>
<span class="regexp">			window.onload = function () {</span>
<span class="regexp">				const email = document.querySelector('#email'); /</span><span class="regexp">/获取email表单元素</span>
<span class="regexp">				const info = document.querySelector('.info'); /</span><span class="regexp">/提示信息</span>
<span class="regexp">				email.onblur = function () {</span>
<span class="regexp">					let reg = /</span>^[A-Za-z0<span class="number">-9</span>]+([_\.][A-Za-z0<span class="number">-9</span>]+)*@([A-Za-z0<span class="number">-9</span>\-]+\.)+[A-Za-z]{<span class="number">2</span>,<span class="number">6</span>}$/; <span class="comment">//邮箱正则表达式</span>
					<span class="keyword">let</span> emailValue = email.value;
					<span class="keyword">if</span>(!reg.test(emailValue)) { <span class="comment">//邮箱正确性验证</span>
						info.innerHTML = <span class="string">'邮箱地址有误，请重新输入'</span>;
						<span class="keyword">return</span> info.className = <span class="string">'defail'</span>;
					}
					<span class="comment">//使用封装好的ajax</span>
					ajax({
						type: <span class="string">'get'</span>, 
						url: <span class="string">'http://localhost:3000/regtest'</span>, <span class="comment">//路径</span>
						data: {
							emailValue <span class="comment">//传递邮箱地址给服务进行判断</span>
						},
						success: <span class="function"><span class="params">data</span> =></span> {
							info.innerHTML = data.message; 
							info.className = <span class="string">'success'</span>
						},
						error: <span class="function"><span class="params">data</span> =></span> {
							info.innerHTML = data.message;
							info.className = <span class="string">'defail'</span>;
						}
					});
				}
			}
		<<span class="regexp">/script></span>
<span class="regexp">	</</span>head>
	<body>
		<div <span class="class"><span class="keyword">class</span></span>=<span class="string">"container"</span>>
			<label <span class="keyword">for</span>=<span class="string">"email"</span>>邮箱地址：<<span class="regexp">/label></span>
<span class="regexp">			<input type="email" id="email" placeholder="请输入邮箱地址" /</span>>
			<span <span class="class"><span class="keyword">class</span></span>=<span class="string">"info"</span>><<span class="regexp">/span></span>
<span class="regexp">		</</span>div>
	<<span class="regexp">/body></span>
<span class="regexp"></</span>html><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="三、node-js作为服务器-数据交互"><a href="#三、node-js作为服务器-数据交互" class="headerlink" title="三、node.js作为服务器-数据交互"></a>三、node.js作为服务器-数据交互</h2><pre class="line-numbers language-highlight js"><span class="comment"><code class="language-highlight js"><span class="comment">//服务端</span>
<span class="comment">//导入express框架</span>
<span class="keyword">const</span> express = <span class="built_in">require</span>(<span class="string">'express'</span>);
<span class="keyword">const</span> server = express();
<span class="keyword">const</span> path = <span class="built_in">require</span>(<span class="string">'path'</span>);
<span class="comment">//方法1.设置跨域请求-方法很多看个人喜好</span>
server.use(<span class="function">(<span class="params">req, res, next</span>) =></span> {
	res.header(<span class="string">'Access-Control-Allow-Origin'</span>,<span class="string">'*'</span>);
	<span class="built_in">console</span>.log(<span class="string">'with client connection...\nclient address:'</span>+req.socket.remoteAddress+<span class="string">' client post:'</span>+req.socket.remotePort);
	next();
})
<span class="comment">//方法2：也可直接通过服务端路径访问</span>
server.use(express.static(__dirname));<span class="comment">//服务端路径：http://localhost:3000/xxx.html</span>
<span class="comment">//进行邮箱唯一性判断</span>
	<span class="keyword">let</span> emailData = [];
server.get(<span class="string">'/regtest'</span>, (req, res) => { <span class="comment">//入口</span>
	<span class="keyword">for</span>(<span class="keyword">let</span> i=<span class="number">0</span>; i<emailData.length; i++) {
		<span class="keyword">if</span>(emailData[i] == req.query.emailValue) {
			<span class="keyword">return</span> res.send({<span class="attr">message</span>: <span class="string">'邮箱地址已存在，请重新注册'</span>});
		}
	}
	res.send({<span class="attr">message</span>: <span class="string">'邮箱地址可用'</span>});
	emailData.push(req.query.emailValue);
	emailData = [...new <span class="built_in">Set</span>(emailData)]; <span class="comment">//对数组重新去重操作</span>
	
}).listen(<span class="number">3000</span>, () => { <span class="comment">//开启服务器</span>
	<span class="built_in">console</span>.log(<span class="string">'server is running...'</span>);
})<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h2 id="四、效果图"><a href="#四、效果图" class="headerlink" title="四、效果图"></a>四、效果图</h2><p>自行操作获取，可以熟悉跨域操作，和node.js作为服务器，不需要额为安装其他的web服务器，通吃前后端…</p>
<h2 id="五-ajax-介绍"><a href="#五-ajax-介绍" class="headerlink" title="五 ajax 介绍"></a>五 ajax 介绍</h2><h3 id="5-1-Json字符串与JSON对象互换"><a href="#5-1-Json字符串与JSON对象互换" class="headerlink" title="5.1 Json字符串与JSON对象互换"></a>5.1 Json字符串与JSON对象互换</h3><h4 id="JSON字符串转换为JSON对象"><a href="#JSON字符串转换为JSON对象" class="headerlink" title="JSON字符串转换为JSON对象"></a>JSON字符串转换为JSON对象</h4><ol>
<li>eval() 将字符串转换为js代码块 ,转换为JSON对象 =&gt; eval(‘(‘+ json字符串+’)’)</li>
<li>json.parseJSON() </li>
<li>JSON.parse(json)</li>
</ol>
<h4 id="JSON对象转换为JSON-字符串"><a href="#JSON对象转换为JSON-字符串" class="headerlink" title="JSON对象转换为JSON 字符串"></a>JSON对象转换为JSON 字符串</h4><ol>
<li>json.toJSONString()</li>
<li>JSON.stringify();</li>
</ol>
<h3 id="5-2-AJAX的优点"><a href="#5-2-AJAX的优点" class="headerlink" title="5.2 AJAX的优点"></a>5.2 AJAX的优点</h3><ol>
<li>无需刷新页面更新数据</li>
<li>异步与服务器通信(不需要打断用户的操作，反应更加迅速)</li>
<li>减轻服务端的压力(把一些服务端负担的工作交给客户端处理，减轻了带宽的负担，和成本).</li>
<li>标准化被广泛使用</li>
<li>与web代码相分离,有利于提高工作效率</li>
</ol>
<h3 id="5-3-AJAX的缺点"><a href="#5-3-AJAX的缺点" class="headerlink" title="5.3 AJAX的缺点"></a>5.3 AJAX的缺点</h3><ol>
<li>动态更新页面，用户无法回到上一个页面的状态</li>
<li>AJAX有安全性问题，就相当于与企业数据直接建立了一条通道</li>
<li>对搜索引擎支持较弱，对搜索引擎的优化不好</li>
<li>会破坏程序的异常处理机制</li>
<li>AJAX对移动端的支持不好</li>
</ol>
<h3 id="5-4-AJAX的使用"><a href="#5-4-AJAX的使用" class="headerlink" title="5.4 AJAX的使用"></a>5.4 AJAX的使用</h3><h4 id="5-4-1-创建ajax对象"><a href="#5-4-1-创建ajax对象" class="headerlink" title="5.4.1 创建ajax对象"></a>5.4.1 创建ajax对象</h4><p>const xhr = new XMLHttpRequest()</p>
<h4 id="5-4-2-初始化请求"><a href="#5-4-2-初始化请求" class="headerlink" title="5.4.2 初始化请求"></a>5.4.2 初始化请求</h4><p>xhr.open(method, url, daync); </p>
<p>method：请求方式</p>
<ul>
<li>get 获取get请求的数据</li>
<li>head 获取报文头</li>
<li>post 获取post请求方式的数据</li>
<li>put 从客户端向服务端传递的数据取代指定的文档内容</li>
<li>delete请求服务器删除指定的页面</li>
<li>connect 预留给能够将连接改为管道方式的代理服务器</li>
<li>options 允许客户端查看服务端的性能</li>
<li>trace 回显服务端收到的请求，主要用测试和诊断</li>
</ul>
<p>url服务器中文件的地址</p>
<p>daync 默认为true 异步，false为同步</p>
<h4 id="5-4-3-发送请求"><a href="#5-4-3-发送请求" class="headerlink" title="5.4.3 发送请求"></a>5.4.3 发送请求</h4><p>xhr.send(); // get请求的数据以键值对的形式放到地址栏中，post请求的数据放到send()中。</p>
<p>post请求还需要设置请求头：模拟表单post来传递数据</p>
<p>xhr.setRequestHeader(‘Content-type’, ‘application-x-www-form-urlencoded’);</p>
<h5 id="get-和post请求的区别"><a href="#get-和post请求的区别" class="headerlink" title="get 和post请求的区别"></a>get 和post请求的区别</h5><ol>
<li>语义化不一样：get倾向于从服务端获取数据， post倾向于向服务端传递数据</li>
<li>传递参数的方式不一样：get请求直接在地址栏后面拼接，post请求在请求体中传递</li>
<li>参数的大小限制：get请求一般不大于2kb，post请求理论上没有限制</li>
<li>缓存能力：get会被浏览器主动缓存，post不会被浏览器主动缓存</li>
<li>安全性能：get请求安全性较低，post请求安全性相对较高</li>
</ol>
<h5 id="请求-响应状态"><a href="#请求-响应状态" class="headerlink" title="请求/响应状态"></a>请求/响应状态</h5><p>readyState 响应状态</p>
<ul>
<li>0 请求未初始化</li>
<li>1 服务器连接成功</li>
<li>2 请求已接收</li>
<li>3 请求处理中</li>
<li>4 请求已完成</li>
</ul>
<p>当 readyState 改变时就会触发 onreadystatechange 事件</p>
<p>status状态码：http请求的状态码</p>
<ul>
<li><table>
<thead>
<tr>
<th>1**</th>
<th>信息，服务器收到请求，需要请求者继续执行操作</th>
</tr>
</thead>
<tbody><tr>
<td>2**</td>
<td>成功，操作被成功接收并处理</td>
</tr>
<tr>
<td>3**</td>
<td>重定向，需要进一步的操作以完成请求</td>
</tr>
<tr>
<td>4**</td>
<td>客户端错误，请求包含语法错误或无法完成请求</td>
</tr>
<tr>
<td>5**</td>
<td>服务器错误，服务器在处理请求的过程中发生了错误</td>
</tr>
</tbody></table>
</li>
</ul>
<h3 id="5-4-4-接收数据"><a href="#5-4-4-接收数据" class="headerlink" title="5.4.4 接收数据"></a>5.4.4 接收数据</h3><p>当readyState为 4 且 status为 200 时，表示请求已完成，成功得到响应结果xhr.onreadystatechange=function (){  if (xhr.readyState4) { // 请求完成    if (xhr.status200) { //ok 成功      alert( xhr.responseText ); // 得到响应结果    } else{      alert( xhr.status ); // 弹出失败的状态码    };  };}<br>xhr.responseText 获得文本形式的响应数据xhr.responseXML 获得 XML 形式的响应数据</p>
<script>
        document.querySelectorAll('.github-emoji')
          .forEach(el => {
            if (!el.dataset.src) { return; }
            const img = document.createElement('img');
            img.style = 'display:none !important;';
            img.src = el.dataset.src;
            img.addEventListener('error', () => {
              img.remove();
              el.style.color = 'inherit';
              el.style.backgroundImage = 'none';
              el.style.background = 'none';
            });
            img.addEventListener('load', () => {
              img.remove();
            });
            document.body.appendChild(img);
          });
      </script>
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/blog/about" rel="external nofollow noreferrer">LanHuiYan</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="http://codehouse9.gitee.io/blog/ad87.html">http://codehouse9.gitee.io/blog/ad87.html</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/blog/about" target="_blank">LanHuiYan</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/blog/tags/ajax/">
                                    <span class="chip bg-color">ajax</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/blog/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/blog/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/blog/medias/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/blog/medias/reward/wechat.jpg" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/blog/flex.html">
                    <div class="card-image">
                        
                        
                        <img src="/blog/medias/featureimages/4.jpg" class="responsive-img" alt="Flex弹性布局">
                        
                        <span class="card-title">Flex弹性布局</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            flex弹性布局的特点
操作方便，布局简单，移动端运用非常广泛，如微信小程序开发。
运用flex布局，可以对行内元素设置宽高，不需要设置为行内块状元素或者块状元素。
对父盒子设置flex布局后，子盒子中的float，clear，vertic
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2020-08-14
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/blog/categories/%E5%89%8D%E7%AB%AF/" class="post-category">
                                    前端
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/blog/tags/flex/">
                        <span class="chip bg-color">flex</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/blog/4688.html">
                    <div class="card-image">
                        
                        
                        <img src="/blog/medias/featureimages/5.jpg" class="responsive-img" alt="前端面试题">
                        
                        <span class="card-title">前端面试题</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            一.es6新特性es6 ECMAscript js的规范

let变量的特点:(1) 不存在变量的提升(2)同一个作用域下不能重复定义同一个变量(3)存在严格的作用域    var属于函数作用域  let块级作用域(4)存在暂时性死区
co
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2020-08-01
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/blog/categories/%E5%89%8D%E7%AB%AF/" class="post-category">
                                    前端
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/blog/tags/js/">
                        <span class="chip bg-color">js</span>
                    </a>
                    
                    <a href="/blog/tags/es6/">
                        <span class="chip bg-color">es6</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>


<script>
    $('#articleContent').on('copy', function (e) {
        // IE8 or earlier browser is 'undefined'
        if (typeof window.getSelection === 'undefined') return;

        var selection = window.getSelection();
        // if the selection is short let's not annoy our users.
        if (('' + selection).length < Number.parseInt('500')) {
            return;
        }

        // create a div outside of the visible area and fill it with the selected text.
        var bodyElement = document.getElementsByTagName('body')[0];
        var newdiv = document.createElement('div');
        newdiv.style.position = 'absolute';
        newdiv.style.left = '-99999px';
        bodyElement.appendChild(newdiv);
        newdiv.appendChild(selection.getRangeAt(0).cloneContents());

        // we need a <pre> tag workaround.
        // otherwise the text inside "pre" loses all the line breaks!
        if (selection.getRangeAt(0).commonAncestorContainer.nodeName === 'PRE') {
            newdiv.innerHTML = "<pre>" + newdiv.innerHTML + "</pre>";
        }

        var url = document.location.href;
        newdiv.innerHTML += '<br />'
            + '来源: codeHose9<br />'
            + '文章作者: LanHuiYan<br />'
            + '文章链接: <a href="' + url + '">' + url + '</a><br />'
            + '本文章著作权归作者所有，任何形式的转载都请注明出处。';

        selection.selectAllChildren(newdiv);
        window.setTimeout(function () {bodyElement.removeChild(newdiv);}, 200);
    });
</script>


<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/blog/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/blog/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/blog/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/blog/libs/codeBlock/codeShrink.js"></script>


<!-- 代码块折行 -->


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/blog/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




    <footer class="page-footer bg-color">
    
        <link rel="stylesheet" href="/blog/libs/aplayer/APlayer.min.css">
<style>
    .aplayer .aplayer-lrc p {
        
        display: none;
        
        font-size: 12px;
        font-weight: 700;
        line-height: 16px !important;
    }

    .aplayer .aplayer-lrc p.aplayer-lrc-current {
        
        display: none;
        
        font-size: 15px;
        color: #42b983;
    }

    
    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body {
        left: -66px !important;
    }

    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body:hover {
        left: 0px !important;
    }

    
</style>
<div class="">
    
    <div class="row">
        <meting-js class="col l8 offset-l2 m10 offset-m1 s12"
                   server="netease"
                   type="playlist"
                   id="503838841"
                   fixed='true'
                   autoplay='true'
                   theme='#42b983'
                   loop='all'
                   order='random'
                   preload='auto'
                   volume='0.5'
                   list-folded='true'
        >
        </meting-js>
    </div>
</div>

<script src="/blog/libs/aplayer/APlayer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script>

    
    <div class="container row center-align" style="margin-bottom: 15px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            <span id="year">2020</span>
            <a href="/blog/about" target="_blank">LanHuiYan</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br>
            
            &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                class="white-color">42.8k</span>&nbsp;字
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <span id="sitetime">载入运行时间...</span>
            <script>
                function siteTime() {
                    var seconds = 1000;
                    var minutes = seconds * 60;
                    var hours = minutes * 60;
                    var days = hours * 24;
                    var years = days * 365;
                    var today = new Date();
                    var startYear = "2020";
                    var startMonth = "6";
                    var startDate = "16";
                    var startHour = "0";
                    var startMinute = "0";
                    var startSecond = "0";
                    var todayYear = today.getFullYear();
                    var todayMonth = today.getMonth() + 1;
                    var todayDate = today.getDate();
                    var todayHour = today.getHours();
                    var todayMinute = today.getMinutes();
                    var todaySecond = today.getSeconds();
                    var t1 = Date.UTC(startYear, startMonth, startDate, startHour, startMinute, startSecond);
                    var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
                    var diff = t2 - t1;
                    var diffYears = Math.floor(diff / years);
                    var diffDays = Math.floor((diff / days) - diffYears * 365);
                    var diffHours = Math.floor((diff - (diffYears * 365 + diffDays) * days) / hours);
                    var diffMinutes = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours) /
                        minutes);
                    var diffSeconds = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours -
                        diffMinutes * minutes) / seconds);
                    if (startYear == todayYear) {
                        document.getElementById("year").innerHTML = todayYear;
                        document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffDays + " 天 " + diffHours +
                            " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                    } else {
                        document.getElementById("year").innerHTML = startYear + " - " + todayYear;
                        document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffYears + " 年 " + diffDays +
                            " 天 " + diffHours + " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                    }
                }
                setInterval(siteTime, 1000);
            </script>
            
            <br>
            
            <span id="icp"><img src="/blog/medias/icp.png" style="vertical-align: text-bottom;" />
                <a href="http://www.beian.miit.gov.cn/" target="_blank">备案信息：赣ICP备20200706号-1</a>
            </span>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/codeHouse9/codeHouse9.github.io" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:3295849115@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=3295849115" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 3295849115" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>





    <a href="https://www.zhihu.com/people/wei-mi-de-xia-tian/asks" class="tooltipped" target="_blank" data-tooltip="关注我的知乎: https://www.zhihu.com/people/wei-mi-de-xia-tian/asks" data-position="top" data-delay="50">
        <i class="fab fa-zhihu1">知</i>
    </a>

<!-- 

    <a href="/blog/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>
 -->
</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/blog/js/search.js"></script>
<script type="text/javascript">
$(function () {
    searchFunc("/blog/search.xml", 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/blog/libs/materialize/materialize.min.js"></script>
    <script src="/blog/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/blog/libs/aos/aos.js"></script>
    <script src="/blog/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/blog/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/blog/js/matery.js"></script>

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/blog/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/blog/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    
    <script type="text/javascript" color="0,0,255"
        pointColor="0,0,255" opacity='0.7'
        zIndex="-1" count="66"
        src="/blog/libs/background/canvas-nest.js"></script>
    

    
    
    <script type="text/javascript" size="150" alpha='0.6'
        zIndex="-1" src="/blog/libs/background/ribbon-refresh.min.js" async="async"></script>
    

    
    <script type="text/javascript" src="/blog/libs/background/ribbon-dynamic.js" async="async"></script>
    

    
    <script src="/blog/libs/instantpage/instantpage.js" type="module"></script>
    

<script src="/blog/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"scale":1,"hHeadPos":0.5,"vHeadPos":0.618,"jsonPath":"/blog/live2dw/assets/shizuku.model.json"},"display":{"superSample":2,"width":150,"height":320,"position":"right","hOffset":50,"vOffset":-20},"mobile":{"show":false,"scale":0.8},"react":{"opacityDefault":0.7,"opacityOnHover":0.5},"log":false});</script></body>

</html>
